import {Component, ViewChild, AfterViewInit} from '@angular/core';

@Component({
    selector: 'my-com',
    template: '<button>我是一个按钮</button>'
})
export class MyCom{
    ngOnInit() {
        alert(123)
    }
}

@Component({
    template: '<my-com #myCom></my-com>'
    // directives: [MyCom]
})

export class MyPage implements AfterViewInit{
    // @ViewChild(MyCom) myComA;
    @ViewChild('myCom') myComB; 

    public constructor(){
        // console.log(this.myComA);//undefined
        console.log(this.myComB);//undefined
    }

    public ngAfterViewInit(){
        // console.log(this.myComA);//输出MyCom对象
        console.log(this.myComB);//输出MyCom对象
        // console.log(this.myComA == this.myComB);//true
    }
}

